package com.zeus.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zeus.mapper.GoodsMapper;
import com.zeus.pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 冯扬龙
 * @date 2021/4/17 17:20
 */
@Service
public class GoodsServiceImpl  implements  GoodsService{

    @Autowired
    private GoodsMapper goodsMapper;
//点击不同的商品列表跳转到专门属于此商品的详细页面，点击按钮，传过来的参数是cid
    public PageInfo<Goods> showGoods(int cid, int pageIndex, int pageSize) {
//        设置开始查询的位置以及查询多少条记录
        PageHelper.startPage(pageIndex,pageSize);
//        查询当前页数据
        List<Goods> goodsList = goodsMapper.showGooods(cid);
//        组装对象
        PageInfo<Goods> pageInfo = new PageInfo<Goods>(goodsList);
        return pageInfo;
    }

//前端通过点击传一个goodsId过来，然后进数据库查询，把对象组装好以后返回一个goods类型的对象

    public Goods selectGoodsByGoodsId(int goodsId) {
        return goodsMapper.selectGoodsByGoodsId(goodsId);
    }
}
